package com.learn.controller;

import com.learn.base.ApiResult;
import com.learn.dto.req.AddProductItemReq;
import com.learn.dto.req.QueryProductItemDetailReq;
import com.learn.dto.req.UpdateProductItemReq;
import com.learn.dto.resp.QueryProductItemDetailResp;
import com.learn.service.ProductItemService;
import com.learn.utils.GlobalTokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping (value = "productItem")
@Service
public class ProductItemController
{
	@Autowired
	private ProductItemService productItemService;

	//新增
	@PostMapping("/save")
	public ApiResult<Boolean> save(@RequestBody AddProductItemReq req){
		log.info("save 的請求參數是 {}" , req);
		log.info ("======{}", GlobalTokenUtil.getUserAccount ());
		return productItemService.saveProductItem(req);
	}

	//详情查询
	@PostMapping("/detail")
	public ApiResult<QueryProductItemDetailResp> detail(@RequestBody QueryProductItemDetailReq req){
		log.info("detail 的請求參數是 {}" , req);
		log.info ("======{}", GlobalTokenUtil.getUserAccount ());
		return productItemService.queryProductItemDetail (req);
	}

	//更新
	@PostMapping("/update")
	public ApiResult<Boolean> update(@RequestBody UpdateProductItemReq req){
		log.info("update 的請求參數是 {}" , req);
		log.info ("======{}", GlobalTokenUtil.getUserAccount ());
		return productItemService.updateProductItem (req);
	}
}
